﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using SSHTool.Core.Message;
using System;

namespace SSHTool.ViewModel
{
    public class ConnectionViewModel : ObservableObject
    {
        private int _id;
        private string _name;
        private string _password;
        private string _host;
        private int _port;
        private string _userName;
        private string _authType;
        private string _description;

        public int Id { get => _id; set => SetProperty(ref _id, value); }

        public string Name { get => _name; set => SetProperty(ref _name, value); }

        public string Password { get => _password; set => SetProperty(ref _password, value); }

        public string Host { get => _host; set => SetProperty(ref _host, value); }

        public int Port
        {
            get => _port; set => SetProperty(ref _port, value);
        }

        public string UserName
        {
            get => _userName; set => SetProperty(ref _userName, value);
        }

        public string AuthType { get => _authType; set => SetProperty(ref _authType, value); }

        public string Description { get => _description; set => SetProperty(ref _description, value); }

        public RelayCommand ItemClickCmd => new RelayCommand(ItemClick);

        private void ItemClick()
        {
            string code = Guid.NewGuid().ToString();

            NavItemViewModel model = new NavItemViewModel
            {
                Code = code,
                Name = Name,
                ImagePath = @"Resources\Images\connection.png",
                PagePath = @"View\CmdPage.xaml"
            };

            WeakReferenceMessenger.Default.Send(new NewTabItemMessage(this, model));
        }
    }
}
